/*
 * Copyright (c) 2024. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.huawei.csi.tool.domain.score;

import javafx.scene.control.TreeItem;

/**
 * 开发规则：遵循仓颉文件约定 (30)
 *
 * @author lxw
 */
public class DevScore extends AbstractScore {
    /**
     * 使用OSI批准过的License (10)
     */
    private int licenseScore = 10;
    /**
     * 提供有效的readme文件 (10)
     */
    private int readmeScore = 10;
    /**
     * 提供有效的changelog文件 (10)
     */
    private int changelogScore = 10;

    public DevScore() {
        super.beforeScore = licenseScore + readmeScore + changelogScore;
    }

    /**
     * 计算得分 校验
     *
     * @param verifyName    判断是校验类型
     * @param verifySuccess 校验是否成功
     **/
    public void calculateScore(String verifyName, Boolean verifySuccess) {
        switch (verifyName) {
            case "LICENSE":
                if (!verifySuccess) {
                    licenseScore = 0;
                }
                break;
            case "CHANGELOG":
                if (!verifySuccess) {
                    changelogScore = 0;
                }
                break;
            case "README":
                if (!verifySuccess) {
                    readmeScore = 0;
                }
                break;
            default:

        }
    }

    @Override
    public int beforeVerifyScore() {
        return super.beforeScore;
    }

    @Override
    public int afterVerifyScore() {
        return licenseScore + readmeScore + changelogScore;
    }

    @Override
    @SuppressWarnings("all")
    public TreeItem<String> treeItem() {
        TreeItem<String> root = new TreeItem<>("遵循仓颉文件约定（" + afterVerifyScore() + "/" + beforeScore + ")");
        TreeItem<String> readmeTreeItem = new TreeItem<>(readmeScore + "/" + 10 + " 提供有效的 readme 文件");
        TreeItem<String> changelogTreeItem = new TreeItem<>(changelogScore + "/" + 10 + " 提供有效的 changelog 文件");
        TreeItem<String> licenseTreeItem = new TreeItem<>(licenseScore + "/" + 10 + " 使用OSI批准过的 license 文件");
        root.getChildren().addAll(readmeTreeItem, changelogTreeItem, licenseTreeItem);
        return root;
    }

    public int getLicenseScore() {
        return licenseScore;
    }

    public void setLicenseScore(int licenseScore) {
        this.licenseScore = licenseScore;
    }

    public int getReadmeScore() {
        return readmeScore;
    }

    public void setReadmeScore(int readmeScore) {
        this.readmeScore = readmeScore;
    }

    public int getChangelogScore() {
        return changelogScore;
    }

    public void setChangelogScore(int changelogScore) {
        this.changelogScore = changelogScore;
    }
}
